<style>
  .header-font {
    font-size: 15px;
    font-weight: bold;
  }
  .line {
    margin: 10px 0;
    width: 100%;
    border: 0.5px solid rgb(218, 218, 218);
  }
  .table {
    margin-top: 10px;
  }
  .admin-message-form {
    margin-bottom: -10px;
  }
  .paging {
    float:right;
    margin-top:10px;
  }
  .send-message-btn {
    margin-bottom: 10px;
    margin-top: -46px;
    float: right;
  }
</style>
<template>
  <div>
    <div class='header-font'>
      <Icon type="md-apps" />
      <span>运营数据</span>
    </div>
    <div class="line"></div>
    <operate-data-form
      @on-success-valid="handleSubmit"
      class="admin-message-form"
      >
    </operate-data-form>
    <Table
      class="table"
      :columns="columns"
      :data="historyData"
      :loading="loading"
      border>
    </Table>
    <table-page
      class="paging"
      :dataCount="dataCount"
      @change-page="changePage"
      @change-page-size="changePageSize"
      :pageSize="pageSize">
    </table-page>
  </div>
</template>
<script>
import {
  mapActions,
  mapState
} from 'vuex'
import TablePage from '_c/table-page'
import OperateDataForm from '_c/operate-data-form'
export default {
  components: {
    OperateDataForm,
    TablePage
  },
  data () {
    return {
      page: 1,
      title: '数据统计运营数据',
      confirmData: {},
      editData: null,
      playload: null,
      rows: 20,
      loading: true,
      modalState: false,
      templateState: false,
      confirmModal: false,
      columns: [
        {
          title: '序号',
          type: 'index2',
          width: 80,
          align: 'center',
          render: (h, params) => {
            return h('span', params.index + (this.page - 1) * this.pageSize + 1)
          }
        },
        // {
        //   title: '创建日期',
        //   key: 'ctime',
        //   minWidth: 150,
        //   align: 'center'
        // },
        {
          title: '商户姓名',
          key: 'company',
          minWidth: 150,
          align: 'center'
        },
        {
          title: '意向客户数',
          key: 'allcst',
          minWidth: 150,
          align: 'center'
        },
        {
          title: '到店客户数',
          key: 'comecst',
          minWidth: 150,
          align: 'center'
        },
        {
          title: '成单客户数',
          key: 'ordercst',
          minWidth: 150,
          align: 'center'
        }
        // {
        //   title: '操作',
        //   key: 'cz',
        //   minWidth: 120,
        //   align: 'center',
        //   render: (h, params) => {
        //     return h('div', [
        //       h('Button', {
        //         props: {
        //           type: 'primary',
        //           size: 'small',
        //           ghost: 'ghost'
        //         },
        //         style: {
        //           marginRight: '5px'
        //         },
        //         on: {
        //           click: () => {
        //             this.handleClick(params.row.id, params.row)
        //           }
        //         }
        //       }, '查看')
        //     ])
        //   }
        // }
      ]
    }
  },
  computed: {
    ...mapState({
      operateDataList: state => state.operateData.operateDataList,
      dataCount: state => state.operateData.operateDataDataCount,
      historyData: state => state.operateData.operateDataHistoryData,
      pageSize: state => state.operateData.operateDataPageSize,
      row: state => state.operateData.row
    })
  },
  methods: {
    ...mapActions([
      'getOperateDataList',
      'getOperateDataCurrentRow',
      'changeOperateDataPage',
      'changeOperateDataPageSize'
    ]),
    handleSubmit (playload) {
      this.loading = true
      this.playload = playload
      // console.log(playload)
      this.getOperateDataList({
        ...playload,
        rows: this.rows
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    },
    changePage (index) {
      this.loading = true
      this.page = index
      this.changeOperateDataPage(index)
      this.getOperateDataList({
        page: index,
        rows: this.rows,
        ...this.playload
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    },
    changePageSize (value) {
      this.loading = true
      this.rows = value
      this.changeOperateDataPageSize(value)
      this.changePage(this.page)
      this.getOperateDataList({
        rows: value,
        ...this.playload
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    }
  },
  created () {
    this.getOperateDataList({}).then((res) => {
      if (res.data.state === '000') {
        this.loading = false
      }
    })
  }
}
</script>
